package org.ysu.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.ysu.service.RoleResourceService;
import org.ysu.service.SysResourceService;
import org.ysu.vo.ResultVO;
import org.ysu.vo.RoleResourceVO;

import javax.annotation.Resource;

/**
 * <p>
 * 角色与权限关联表 前端控制器
 * </p>
 *
 * @author CaoYuJia
 * @since 2024-08-19
 */
@RestController
@RequestMapping("/roleResource")
public class RoleResourceController {
    @Resource
    SysResourceService sysResourceService;
    @Resource
    RoleResourceService roleResourceService;
    @GetMapping("/getResource")
    ResultVO<RoleResourceVO> getResurce(Long roleId) {
        return ResultVO.success(new RoleResourceVO(sysResourceService.getList(), roleResourceService.getByRoleId(roleId)));
    }
    @PostMapping("/save")
    ResultVO<Boolean> save(Long roleId, Long[] menuIds, Long[] btnIds) {
        return ResultVO.success(roleResourceService.save(roleId, menuIds, btnIds), "保存成功");
    }
}
